﻿// Function handle all cross links
// contain ajax helper class to
// using for ajax action link request
function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

//cheeck for Decimal
function IsDecimal(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function isNumberKey(evt) {
	evt = evt || window.event;
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}

function isPhoneExtNumber(evt) {
	evt = evt || window.event;
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	// check charcode, it's ok if user enter space,(,),-, del character (charCode for + is 43)
	if (charCode == 32 || charCode == 45 || charCode == 46)
		return true;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}

function isPhoneNumber(evt) {
	evt = evt || window.event;
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	
	// check charcode, it's ok if user enter space,(,),-, del character (charCode for + is 43)
	if (charCode == 32 || charCode == 40 || charCode == 41 || charCode == 45 || charCode == 46)
	    return true;
    
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;	

	return true;
}

$(document).ready(function () {
    $(".various").fancybox({
        maxWidth: 770,
        maxHeight: 600,
        fitToView: false,
        width: '80%',
        height: '80%',
        autoSize: false,
        closeClick: false,
        openEffect: 'none',
        closeEffect: 'none'
    });
});

// Close popup error request
// When have an action call a ajax function
// And this request is failure
function closePopupError() {
    $('#popupErrorRequest').hide();
    $('#popup').hide();
    $('#notification').hide();
    $('#fancybox-overlay').hide();
    $('.popup-wrapper').hide();
}
function closePopup() {
    $('#popupErrorRequest').hide();
    $('#popup').hide();
    $('#notification').hide();
    $('#fancybox-overlay').hide();
    $('.fancybox-wrap').hide();
    $('.popup-wrapper').hide();
}
function showPopupError() {
    $('#fancybox-overlay').show();
    $('#popupErrorRequest').showPopup({
        width: 450
    });
}

function popup(url) {
    var width = 900;
    var height = 700;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=1';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open(url, 'windowname5', params);
    if (window.focus) { newwin.focus() }
    return false;
}

function PopupNewWindow(url, params, width, height) {
    win1 = window.open(url, 'Profile', params);
    win1.moveTo(screen.width / 2 - width, screen.height / 2 - height)
}

// Progress Bar
function openProcess() {
    $.fancybox($('#showdialog'), {
        padding: 0,
        closeBtn: false,
        helpers: {
            overlay: {
                opacity: 0.2,
                css: {
                    'background-color': '#EFEFEE'
                }
            }
        },
        beforeClose: function () {
            return false;
        }
    });
    $('.fancybox-skin').show();
    $('#fancybox-overlay').show();
}
function hideProcess() {
    $('#showdialog').hide();
    $('.fancybox-skin').hide();
    $('#fancybox-overlay').hide();
    $('.overlay-fixed').hide();
}

/* Config validation */
ko.validation.configure({
    registerExtenders: true,
    messagesOnModified: true,
    insertMessages: true,
    parseInputAttributes: true,
    messageTemplate: null,
    decorateElement: true,
    errorClass: "error",
    errorMessageClass: "error-desc"
});

